function [Micro, Macro] = Ddavid_get_micro_macro_prf(TrueLabel, PreLabel)

N = size(TrueLabel, 1);
M = size(TrueLabel, 2);

P = zeros(1, M);
R = zeros(1, M);
F = zeros(1, M);
TPSum = 0.0;
FPSum = 0.0;
FNSum = 0.0;

Mat = zeros(2, 2, M);
for i = 1:M
    Mat(:, :, i) = confusionmat(TrueLabel(:, i), PreLabel(:, i), 'order', [1, -1]);
    if(Mat(1, 1, i) == 0)
        P(1, i) = 0;
        R(1, i) = 0;
    else
        P(1, i) = Mat(1, 1, i) / (Mat(1, 1, i) + Mat(2, 1, i));
        R(1, i) = Mat(1, 1, i) / (Mat(1, 1, i) + Mat(1, 2, i));
    end
    F(1, i) = 2 * P(1, i) * R(1, i) / (P(1, i) + R(1, i));
    TPSum = TPSum + Mat(1, 1, i);
    FPSum = FPSum + Mat(2, 1, i);
    FNSum = FNSum + Mat(1, 2, i);
end

Micro.Precision = TPSum / (TPSum + FPSum);
Micro.Recall = TPSum / (TPSum + FNSum);
Micro.F1 = 2 * Micro.Precision * Micro.Recall / (Micro.Precision + Micro.Recall);

Macro.Precision = mean(P);
Macro.Recall = mean(R);
Macro.F1 = 2 * Macro.Precision * Macro.Recall / (Macro.Precision + Macro.Recall);
